<template>
  <div class="header">
    <div class="headerleft">
      <div class="icon">
        <el-icon @click="userstor.isicon()">
          <!-- userstor.menuFold?<Fold />:<Expand /> -->
          <component :is="userstor.menuFold ? 'Expand' : 'Fold'" />
        </el-icon>
      </div>
      <div>
        <el-breadcrumb>
          <el-breadcrumb-item
            v-for="(item, index) in routerlist"
            :key="index"
            :to="{ path: item.path }"
            >{{ item.meta.name }}</el-breadcrumb-item
          >
        </el-breadcrumb>
      </div>
    </div>
    <div>
      <el-dropdown>
        <div class="logo">
          <div class="name" v-if="userinfo&& userinfo.realname">{{ userinfo.realname }}</div>
          <el-avatar :size="30" v-if="userinfo && userinfo.avatar" :src="userinfo.avatar" />
        </div>

        <template #dropdown>
          <el-dropdown-menu>
            <!-- <el-dropdown-item>修改个人信息</el-dropdown-item> -->
            <el-dropdown-item @click="exit()">推出登录</el-dropdown-item>
            <!-- <el-dropdown-item divided @click="exit()"
              >推出登录</el-dropdown-item
            > -->
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import { watch, ref } from "vue";
import { localCache } from "@/ults/cache.js";
import router from "@/router/index.js";
import { useStore } from "@/store/main";
const userstor = useStore();
// 定义路由信息
let routerlist = ref([]);
const initbreadcrumbList = () => {
  routerlist.value = router.currentRoute.value.matched;
  console.log(router.currentRoute.value.matched);
};
// 监听路由的变化
watch(
  () => router,
  () => {
    initbreadcrumbList();
  },
  { deep: true, immediate: true }
);
// 退出
const exit = () => {
  localCache.clearCache();
  router.push("/login");
};
// 获取用户信息
let userinfo = ref({});
userinfo.value = localCache.getCache("userinfo");
console.log(userinfo);
</script>

<style scoped>
.header {
  height: 100%;
  line-height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fff;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
}
.name {
  margin-right: 20px;
}
.headerleft {
  display: flex;
  /* flex-direction: column; */
}
.icon {
  margin-right: 20px;
}
</style>
